let  db  = require('../db.js');

//获取小区列表

exports.getAllVillage  =  async  function () {
    let sql=`
    SELECT  id ,name   FROM  company  

   `
   let  data  = await db.query(sql);
   return data[0];
}

//根据小区ID 获取楼宇列表

exports.getBuildingList =  async function(villageId){
    let  sql=`
    SELECT  id ,name   FROM  company  
    `
    let data  =  await db.query(sql,{villageId});
    return  data[0];
}

//根据楼宇ID 获取 单元列表

exports.getUnitList  = async  function (buildingId){
    let sql=`
    SELECT  id ,name   FROM  company  

    `
    let  data = await db.query(sql,{buildingId});
    return data[0];
}



//注册设备

exports.addEquipment = async function(mac){
    let sql=`
    INSERT INTO equipment(mac)
    VALUES(:mac)
    `
    let data = await db.query(sql,{mac});
    return data[0];
}

//验证mac 地址的唯一性

exports.valicationMac = async function(mac){
    let sql=`
    SELECT *FROM  equipment  WHERE  mac=:mac
    
    `
    let data = await db.query(sql,{mac});
    return data[0];
    }
    
/*******************  数据拼接********************** */

//获取所有的楼宇列表

exports.buildingList  = async  function(){
    let  sql=`
     SELECT  id,name,villageId  FROM  building  where isdelete ='n' 
    `
    let data  =  await db.query(sql);
    return  data[0];    
}

//获取所有的单元列表

exports.unitList   =  async  function(){

    let sql=`
    SELECT  id,name,buildingId  FROM  unit  where isdelete ='n' 
    `
    let  data = await db.query(sql);
    return data[0];
    
}